﻿using System;
using System.Collections.Generic;
using System.Linq;

using Marx;
using Marx.Utils;

namespace Demo
{
    public class ClientManager : Singleton<ClientManager>
    {
        private Dictionary<long, ClientAgent> clients_ = new Dictionary<long, ClientAgent>();

        public ClientAgent Add(ClientAgent client)
        {
            clients_[client.AccountId] = client;
            return client;
        }

        public void Remove(long accountId)
        {
            clients_.Remove(accountId);
        }

        public ClientAgent Get(long accountId)
        {
            if (clients_.TryGetValue(accountId, out var client))
            {
                return client;
            }
            return null;
        }

        public void KickAll()
        {
            foreach (var client in clients_.Values.ToArray())
            {
                client.DestroyImmedately().Coroutine();
            }
            clients_.Clear();
        }
    }

}
